package cn.edu.tju.se.auth.service.impl;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.tju.se.auth.repository.PrivilegeRepository;
import cn.edu.tju.se.auth.enity.Privilege;
import cn.edu.tju.se.auth.enity.Role;
import cn.edu.tju.se.auth.service.PrivilegeService;
import cn.edu.tju.se.auth.service.RoleService;

@Service
public class PrivilegeServiceImpl implements PrivilegeService {

	@Autowired PrivilegeRepository privilegeRepository;
	@Autowired RoleService tjqsRoleService;
	@Override
	public List<Privilege> getAll() {
		return privilegeRepository.findAll();
	}

	@Override
	public void deleteAll(Set<Privilege> priv) {
		privilegeRepository.delete(priv);
	}

	@Override
	public Set<Privilege> getMyPriv(Long id) {
		return tjqsRoleService.get(id).getPrivileges();
	}

	@Override
	public void modifyMyPriv(Long roleId, Set<Privilege> priv) {
		Role r=tjqsRoleService.get(roleId);
		r.setPrivileges(priv);
		tjqsRoleService.update(r);
	}

}
